<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <script>
      const obj = {
        a: 1,
        b: 2,
        [Symbol.iterator]() {
          // 迭代器
          let i = 5;
          return {
            next() {
              i--;
              return { done: !i, value: i };
            },
          };
        },
      };
      for (const v of obj) {
        console.log(v);
      }
    </script>
  </body>
</html>
